package com.unytech.watersoil.entity.security;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Index;

import com.unytech.watersoil.entity.BaseObject;

/**
 * 用户实体类
 * @author LONG
 *
 */
@Entity @Table(name="T_USER")
@GenericGenerator(name="uuidpk",strategy="uuid")  //这个是Hibernate的主键生成器，换框架的时候，此处应注意
//@Inheritance(strategy=InheritanceType.SINGLE_TABLE)  //继承策略
//@DiscriminatorColumn(name="type")  //鉴别器的列
@DiscriminatorValue("0")  //鉴别器的值
public class User extends BaseObject{
	@Id @GeneratedValue(generator="uuidpk")
	@Column(length=18)
	private String uid;                  //用户ID
	
	@Column(length=32,nullable=false,unique=true)
	@Index(name="username_index")        //这个是Hibernate的注解，换框架的时候，此处应注意
	private String username;             //登录账号
	
	@Column(length=32,nullable=false)
	private String realname;
	
	@Column(length=32,nullable=false)
	private String password;              //密码， MD5加密	
	private Integer state = 1;            //账户状态，默认启用
	
	@Temporal(TemporalType.TIMESTAMP) @Column(nullable=false)
	private Date regdate = new Date();    //用户写入时间
	
	@OneToOne()
	private User createperson;            //账户创建人
	
	@ManyToOne(cascade={CascadeType.REFRESH,CascadeType.MERGE}) 
	@JoinColumn(name="unit_id")           //外键列名
	private Unit unit;                    //用户所属单位
	
	@ManyToOne(cascade={CascadeType.REFRESH,CascadeType.MERGE}) 
	@JoinColumn(name="permgroup_id")      //外键列名
	private PermissionGroup permgroup;    //用户所属权限组
	  
	//用户登录信息
	@Transient
	private String loginip;           //用户登录IP
	@Transient     
	private Date logintime;               //用户登录时间
	
	
	public String getUid() {
		return uid;
	}
	public void setUid(String uid) {
		this.uid = uid;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Unit getUnit() {
		return unit;
	}
	public void setUnit(Unit unit) {
		this.unit = unit;
	}
	public Integer getState() {
		return state;
	}
	public void setState(Integer state) {
		this.state = state;
	}
	public PermissionGroup getPermgroup() {
		return permgroup;
	}
	public void setPermgroup(PermissionGroup permgroup) {
		this.permgroup = permgroup;
	}
	public void setRegdate(Date regdate) {
		this.regdate = regdate;
	}
	public Date getRegdate() {
		return regdate;
	}
	public void setRealname(String realname) {
		this.realname = realname;
	}
	public String getRealname() {
		return realname;
	}
	public void setCreateperson(User createperson) {
		this.createperson = createperson;
	}
	public User getCreateperson() {
		return createperson;
	}
	public void setLogintime(Date logintime) {
		this.logintime = logintime;
	}
	public Date getLogintime() {
		return logintime;
	}
	public void setLoginip(String loginip) {
		this.loginip = loginip;
	}
	public String getLoginip() {
		return loginip;
	}
	  
}
